﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.SharedEntities.EsgResearch;
using Sustainalytics.Synchronization.Interface;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.CompanyWeightsLogic
{
    public class CompanyWeightsCommand : SyncEsgCommand<CompanyWeights>
    {
        private readonly IMongoCollection<CompanyWeights> companyWeightsCollection;

        public CompanyWeightsCommand(IMongoCollection<CompanyWeights> companyWeightsCollection, ILogger logger) : base(logger)
        {
            this.companyWeightsCollection = companyWeightsCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds, Guid? additionalDiscriminator)
        {
            return await companyWeightsCollection.DeleteManyAsync(cw => cw.MatrixId == additionalDiscriminator).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<CompanyWeights> entities)
        {
            await companyWeightsCollection.InsertManyAsync(entities);
        }
    }
}
